package com.zhugang.week01;

/**
 * @program algorithms
 * @description: removeDuplicate
 * @author: chanzhugang
 * @create: 2022/03/24 07:27
 */
public class RemoveDuplicate {

    public static void main(String[] args) {
        RemoveDuplicate removeDuplicate = new RemoveDuplicate();
        int[] nums = new int[]{1, 2, 3, 4, 4, 4, 5, 5};
        int length = removeDuplicate.removeDuplicate(nums);
        System.out.println(length);
    }

    public int removeDuplicate(int[] nums) {
        // [1,2,3,4,4,4,5,5]
        int k = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[k]) {
                k++;
                nums[k] = nums[i];
            }
        }
        return k + 1;
    }
}